import com.itextpdf.kernel.colors.Color;
import com.itextpdf.kernel.colors.DeviceRgb;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.borders.Border;
import com.itextpdf.layout.element.*;
import com.itextpdf.layout.properties.*;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
public class TempTest1 {
    public static void main(String[] args) throws Exception {
        try (   PdfWriter writer = new PdfWriter("D:/tmp/中文测试.pdf");
                PdfDocument pdf = new PdfDocument(writer);
                Document document = new Document(pdf)) {

            // 创建表格（2列）
            Table table = new Table(2);
            // 确保使用分离模式
            table.setBorderCollapse(BorderCollapsePropertyValue.COLLAPSE);
            // 隐藏所有单元格的边框
            table.setBorder(Border.NO_BORDER);

            // 添加单元格
            table.addCell(new Cell().add(new Paragraph("fdfs")));
            table.addCell(new Cell().add(new Paragraph("fd")));
            table.addCell(new Cell().add(new Paragraph("fds")));
            table.addCell(new Cell().add(new Paragraph("dfs")));

            // 创建表格后，强制为所有单元格设置无边框
            for (IElement element : table.getChildren()) {
                if (element instanceof Cell) {
                    Cell cell = (Cell) element;
                    cell.setBorder(Border.NO_BORDER);
                }
            }
            document.add(table);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}